package com.deng.permission.view
{
	import com.deng.common.vo.DispenseOrganizationVo;
	import com.deng.permission.model.PermissionModelLocator;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	import mx.events.FlexEvent;

	public class FirstDispenseCB extends CheckBox
	{
		
		private var tmpId:String;
		public function FirstDispenseCB(){			
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,updateEvt);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function updateEvt(event:MouseEvent):void{
			if(this.selected){//之前选中的，后面要删除
				PermissionModelLocator.getInstance().tmp_second_use_o.replace(tmpId,"");
			}else{//之前没选中，后面要增加
				PermissionModelLocator.getInstance().tmp_second_use_o += tmpId;
			}			
		}
		private function showHandler(event:FlexEvent):void{
			if(this.data != null){
				tmpId = ":"+(this.data as DispenseOrganizationVo).id+":";
			}
			
			if(PermissionModelLocator.getInstance().tmp_second_use_o.indexOf(tmpId) >= 0){				
				this.selected = true;
			}else{
				this.selected = false;
			}
		}
	}
}